package com.wjh.feign.impl;

import com.alibaba.fastjson2.JSON;
import com.wjh.base.ResponseApiData;
import com.wjh.user.request.UpdateAmountRequest;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import com.wjh.feign.IUserFeignClient;

import lombok.extern.slf4j.Slf4j;

/**
 * 用户服务容错/熔断处理
 * 
 * @author wenjianhai
 * @date 2023/6/29
 * @since JDK 17
 */
@Slf4j
@Component
public class UserFeignClientImpl implements FallbackFactory<IUserFeignClient> {

    @Override
    public IUserFeignClient create(Throwable cause) {
        return new IUserFeignClient() {
            /**
             * 更新用户可用金额
             *
             * @param request 请求参数
             * @return ResponseApiData
             * @date 2023-06-29
             * @author wenjianhai
             * @since JDK 17
             */
            @Override
            public ResponseApiData<?> updateAmount(UpdateAmountRequest request) {
                log.error("更新用户可用金额-失败.请求参数:{}, 失败信息:{}", JSON.toJSONString(request), cause.getMessage());
                return ResponseApiData.systemFail("更新用户可用金额失败");
            }
        };
    }
}
